# If you change this name also do it in tests.yml and ci_metrics.yml
name: Tests

on:
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
      - ready_for_review
    paths-ignore:
      # we skip the tests unless the code changes. The problem is that GitHub will run the check anyway if any other
      # file outside the code changed (e.g. the release notes). Hence, we need a second filter down below.
      # keep the list in sync with the paths defined in the `tests.yml` workflow
      - "haystack/**/*.py"
      - "haystack/core/pipeline/predefined/*"
      - "test/**/*.py"
      - "test/test_requirements.txt"

jobs:
  check_if_changed:
    name: Check if changed
    runs-on: ubuntu-latest
    permissions:
      pull-requests: read
    outputs:
      code_changes: ${{ steps.changes.outputs.code_changes }}
    steps:
      - uses: actions/checkout@v4
      - name: Check for changed code
        id: changes
        uses: dorny/paths-filter@ebc4d7e9ebcb0b1eb21480bb8f43113e996ac77a
        with:
          # keep the list in sync with the paths defined in the `tests.yml` workflow
          filters: |
            code_changes:
              - haystack/**/*.py
              - "haystack/templates/predefined/*"
              - test/**/*.py
              - test/test_requirements.txt

  catch-all:
    # Don't run this check if the PR contains both code and non-code changes (e.g. release notes)
    needs: check_if_changed
    if: needs.check_if_changed.outputs.code_changes == 'false'
    name: Catch-all check
    runs-on: ubuntu-latest
    steps:
      - name: Skip tests
        run: echo "Skipped!"
